package cn.itchao.manager.controller;

import cn.itchao.pojo.TbBrand;
import cn.itchao.sellergoods.service.BrandService;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: jinchao
 * @date: 18/7/31 13:34
 * @description: 品牌接口
 */
@RestController
@RequestMapping(value = "/brand")
public class BrandController {

    @Reference
    private BrandService brandService;

    /**
     * @description: 查询品牌列表
     * @param: page  当前页
     * @param: size   每页记录数
     * @return: PageResult
     * @author: jinchao
     * @date:   18/7/31 13:32
     */
    @RequestMapping(value = "findPage",method = RequestMethod.GET)
    public PageResult findPage(int page,int size){
        return this.brandService.findPage(page,size);
    }
    /**
     * @description:新增品牌
     * @param:   brand
     * @return: Result
     * @author: jinchao
     * @date:   18/7/31 14:17
     */
    @RequestMapping(value = "/add")
    public Result add(@RequestBody TbBrand brand){

        try {
            this.brandService.add(brand);
            return new Result(true,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"新增失败");
    }
    /**
     * @description: 根据品牌编号查询品牌信息
     * @param:   id
     * @return: TbBrand
     * @author: jinchao
     * @date:   18/7/31 15:06
     */
    @RequestMapping(value = "/findOne")
    public TbBrand findOne(long id){
        return this.brandService.findOne(id);
    }
    /**
     * @description:根据品牌编号修改品牌信息
     * @param:    brand
     * @return: Result
     * @author: jinchao
     * @date:   18/7/31 15:09
     */
    @RequestMapping(value = "/update")
    public Result update(@RequestBody TbBrand brand){
        try {
            this.brandService.update(brand);
            return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"修改失败");
    }

    /**
     * @description: 批量删除品牌
     * @param:  ids 品牌编号数组
     * @author: jinchao
     * @date:   18/7/31 15:58
     */
    @RequestMapping(value = "/delete")
    public Result delete(Long[] ids){
        try {
            this.brandService.delete(ids);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"删除失败");
    }
    /**
     * @description: 根据条件搜索品牌列表
     * @param:
     * @return: 
     * @author: jinchao
     * @date:   18/8/1 13:05
     */
    @RequestMapping("/search")
    public PageResult search(@RequestBody TbBrand brand,int page,int size){
        return this.brandService.findPage(brand,page,size);
    }

    @RequestMapping("/selectOptionList")
    public List<Map> selectOptionList(){
        return this.brandService.selectOptionList();
    }

}
